/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.arquimedes.jms;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author juanda
 */
public class ClienteJMS {

    public void enviarMensaje() throws Exception {
	// Gets the JNDI context
	Context jndiContext = new InitialContext();
	// Looks up the administered objects
	ConnectionFactory connectionFactory = (ConnectionFactory) jndiContext.lookup("Prueba");
	Topic topic = (Topic) jndiContext.lookup("jms/Prueba");
	// Creates the needed artifacts to connect to the queue
	Connection connection = connectionFactory.createConnection();
	Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
	MessageProducer producer = session.createProducer(topic);
	// Sends a text message to the queue
	TextMessage message = session.createTextMessage();
	message.setText("This is a text message");
	producer.send(message);
	connection.close();
    }
}
